<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>AngularJS&middot;Hello AngularJS</title>
    <link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.2/css/bootstrap.css">
    <style>
        .demo{
            margin-bottom:10px;
            border-top:1px solid #1b926c;
        }
         footer{
             color:#fff;
             background-color: #222;
             border-color: #080808;
             padding-top:60px;
             margin-top:100px;
         }
    </style>
</head>
<body>
<div class="row">
    <nav class="navbar navbar-default navbar-static-top">
        <div class="container-fluid">
            <div class="navbar-header">
                <a class="navbar-brand" href="../index.html">首页</a>
            </div>
            <ul class="nav navbar-nav">
                <li class="active"><a href="javascript:void(0)">Link</a></li>
                <li><a href="javascript:void(0)">Link2</a></li>
            </ul>
        </div>
    </nav>
</div>
 <div class="container" ng-app="MyAPP" ng-init="name= '祖父'">
      <h3>Demo1: 指令示例</h3>
     <br>
      <firsttag></firsttag>
      <br>
      <secondtag value="http://www.shikezhi.com" text="时刻知网站"></secondtag>
      <p secondtag value="http://www.google.com" text="google网站"></p>

     <br>
     <thirdtag value="views/footer"></thirdtag>
 </div>
</body>
</html>
<script src="http://cdn.bootcss.com/angular.js/1.3.8/angular.js" type="text/javascript"></script>
<script>
    var app=angular.module("MyAPP",[]);

    app.directive('firsttag',function(){
        return {
            restrict: "E",
            replace: true,//通常，这种效果只有设置restrict="E"的情况下，才会表现出实际效果。
            template: "<div class='row'>我是指令中的内容...</div>"
        }
    });

    app.directive('secondtag',function(){
        return {
            restrict:"EAC",
            //replace:true, //不设置这个值，默认为false,默认false意味着模板会被当作子元素插入到调用此指令的元素内部
            template: function (elem, attr) {
                return "<a href='" + attr.value + "'>" + attr.text + "</a>";
            }
        }
    });

    app.directive('thirdtag',function(){;
        return {
            restrict:"EAC",
            templateUrl:function(elem,attr){
                return attr.value+".html"
            }
        }
    })
</script>